package 比较排序;

public class MergeSrot {
    public static void sort(int[] arr,int low,int high){
        int mid=(low+high)/2;
        if(low<high){
            sort(arr,low,mid);
            sort(arr,mid+1,high);
            merge(arr,low,mid,high);
        }
    }

    public static void merge(int[] a,int low,int mid, int high){
        int[] temp=new int[high-low+1];
        int i=low;
        int j=mid+1;
        int k=0;

        while(i<=mid && j<=high){
            if(a[i]<a[j])
                temp[k++]=a[i++];
            else
                temp[k++]=a[j++];
        }

        while (i<=mid){
            temp[k++]=a[i++];
        }
        while (j<=high){
            temp[k++]=a[j++];
        }
        for (i = 0; i < temp.length; i++) {
            a[i+low]=temp[i];
        }




    }
}
